package edu.towson.cosc.cosc455.sliao1.markdowncompiler;
import java.io.IOException;
import java.util.*;

public class MysemanticAnalyzer {
	public Stack<String> html = new Stack<String>();
	public String string = "";	
	//convert token to html.
	public void convert(){
		while(!Compiler.validTokens.isEmpty()){
			string = Compiler.validTokens.pop();
			html.push(string);
		}
		
		while(!html.isEmpty()){
			string = html.pop();
			try{
				Compiler.writer.write(tokenToHtml(string));
			}
			catch(IOException e){
				e.printStackTrace();
			}
			Compiler.validTokens.push(string);
		}
	}
	//Convert token to the corresponding html.
	public String tokenToHtml(String token){
		String html = "";
		switch(token){
		case "#START DOCUMENT":
			html = "<html>";
			break;
		case "#END DOCUMENT":
			html = "</html>";
			break;
		case "#START HEAD":
			html = "<head>";
			break;
		case "#END HEAD":
			html = "</head>";
			break;
		case "#START TITLE":
			html = "<title>";
			break;
		case "#END TITLE":
			html = "</title>";
			break;
		case "#START PARAGRAPH":
			html = "<p>";
			break;
		case "#END PARAGRAPH":
			html = "</p>";
			break;
		case "#START BOLD":
			html = "<b>";
			break;
		case "#END BOLD":
			html = "</b>";
			break;
		case "#START ITALICS":
			html = "<i>";
			break;
		case "#END ITALICS":
			html = "</i>";
			break;
		case "#START LIST":
			html = "<ul>";
			break;
		case "#END LIST":
			html = "</ul>";
			break;
		case "START ITEM":
			html = "<li>";
			break;
		case "#END ITEM":
			html = "</li>";
			break;
		case "#NEWLINE":
			html = "<br>";
			break;
		case "#START AUDIO":
			html = "<audio controls> <source src=\" ";
			break;
		case "#END AUDIO":
			html = " \" > </audio>";
			break;
		case "#START VIDEO":
			html = "<iframe src=\""; 
			break;
		case "#END VIDEO":
			html = "\" />";
			break;
		case "#start document":
			html = "<html>";
			break;
		case "#end document":
			html = "</html>";
			break;
		case "#start head":
			html = "<head>";
			break;
		case "#end head":
			html = "</head>";
			break;
		case "#start title":
			html = "<title>";
			break;
		case "#end title":
			html = "</title>";
			break;
		case "#start paragraph":
			html = "<p>";
			break;
		case "#end paragraph":
			html = "</p>";
			break;
		case "#start bold":
			html = "<b>";
			break;
		case "#end bold":
			html = "</b>";
			break;
		case "#start italics":
			html = "<i>";
			break;
		case "#end italics":
			html = "</i>";
			break;
		case "#start list":
			html = "<ul>";
			break;
		case "#end list":
			html = "</ul>";
			break;
		case "start item":
			html = "<li>";
			break;
		case "#end item":
			html = "</li>";
			break;
		case "#newline":
			html = "<br>";
			break;
		case "#start audio":
			html = "<audio controls> <source src=\" ";
			break;
		case "#end audio":
			html = " \" > </audio>";
			break;
		case "#start video":
			html = "<iframe src=\""; 
			break;
		case "#end video":
			html = "\" />";
			break;
		case "#START DEFINE":
			break;
		case "#END DEFINE":
			break;
		case "#NAME":
			break;
		case "#VALUE":
			break;
		case "#START USE":
			break;
		case "#END USE":
			break;
		case "#start define":
			break;
		case "#end define":
			break;
		case "#name":
			break;
		case "#value":
			break;
		case "#start use":
			break;
		case "#end use":
			break;
		default:
			html = token;
			break;
		}
		return html;
	}
}

